import Http from '@@/common/plugins/http.js';
import axios from "axios";

function uploadPhoto2(format) {
    if (format == undefined) format = 'jpg'
        //https://api.hxsapp.com/act/oss/sign/url
    return Http.get('https://api.hxsapp.com/act/oss/sign/url', {
        format: format
    });
}
const uploadWebOss = function(
    bold,
    type
) {
    let that = this;
    return new Promise((resolve, reject) => {
            let data2 = uploadPhoto2(type).then(res => {
                const data = res.data
                if (!data) return;
                const {
                    sign_url,
                    url
                } = data;
                axios({
                        method: "PUT",
                        url: sign_url,
                        data: bold,
                        headers: {
                            'Content-Type': 'text/plain',
                            'X-Oss-Meta-project': 'hxsappact',
                        },
                    })
                    .then(res => {
                        resolve(url)
                    })
                    .catch(error => {
                        console.log("接口报错", error);
                        reject(error)
                    });

            }).catch(error => {
                console.log("uploadPhoto2-error", error);
            });;
        })
        // 返回处理数据
        // 增加catch处理

}

export default uploadWebOss